import { query } from '../services/dashboard'



export default {
  namespace: 'dashboard',
  state: {
    resultList:[]

  },
  subscriptions: {
  setup ({ dispatch, history }) {
      history.listen(location => {
        if (location.pathname === '/dashboard') {
          dispatch({
            type: 'query',
            payload: location.query,
          })
        }
      })
    },
  },
  effects: {
    *query ({
      payload,
    }, { call, put }) {
      const data = yield call(query)
      if(data.success){
        yield put({ type: 'querySuccess',
          payload: {
            resultList:JSON.parse(data.data)
          } })
      }

    },

  },
  reducers: {

    querySuccess (state, { payload }) {
      const { resultList } = payload
      return {
        ...state,
        resultList,
        // ...action.payload,
      }
    },
  },
}
